package com.xjh.him.controller;

import com.xjh.him.annotation.LoginVerify;
import com.xjh.him.dto.friendapply.FriendApplyInfoDTO;
import com.xjh.him.dto.friendapply.FriendHandleApplyDTO;
import com.xjh.him.service.FriendApplyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xjh.tool.dto.ResultDTO;
import org.xjh.tool.vo.AjaxResultVO;


@RestController
@RequestMapping("/friend/apply")
public class FriendApplyController {

    @Autowired
    private FriendApplyServiceImpl friendApplyService;

    //TODO:以下两个接口应该用 rpc 来调用

    @LoginVerify
    @RequestMapping("")
    public AjaxResultVO apply(@RequestBody FriendApplyInfoDTO applyInfoDTO) {
        ResultDTO<Boolean> resultDTO = friendApplyService.apply(applyInfoDTO);
        if (resultDTO.isSuccess()) {
            return AjaxResultVO.getSuccessResult(resultDTO.getResult());
        }
        return AjaxResultVO.getFailureResult(resultDTO.getErrMsg());
    }

    @LoginVerify
    @RequestMapping("/handle")
    public AjaxResultVO handleApply(@RequestBody FriendHandleApplyDTO handleApplyDTO) {
        ResultDTO<Boolean> resultDTO = friendApplyService.handleApply(handleApplyDTO);
        if (resultDTO.isSuccess()) {
            return AjaxResultVO.getSuccessResult(resultDTO.getResult());
        }
        return AjaxResultVO.getFailureResult(resultDTO.getErrMsg());
    }
}
